package cn.wolfcode.luowowo.common.util;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.io.Serializable;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult implements Serializable {
    private boolean success = true;
    private String msg;
    private Object data;
    private int code;

    //构造器
    public JsonResult(boolean success, String msg) {
        this.success = success;
        this.msg = msg;
    }
    public JsonResult(boolean success, String msg, Object data) {
        this.success = success;
        this.msg = msg;
        this.data = data;
    }
    public JsonResult(boolean success, String msg, int code) {
        this.success = success;
        this.msg = msg;
        this.code = code;
    }
    public JsonResult(boolean success) {
        this.success = success;
    }
    public JsonResult(boolean success, Object data) {
        this.success = success;
        this.data = data;
    }

    //成功的结果
    public final static JsonResult SUCCESS = new JsonResult();
    //失败的结果
    public final static JsonResult FAIL = new JsonResult(false);
    //code为102的没登录的结果
    public final static JsonResult UNLOGIN = new JsonResult(false, "请登录", 102);


    public JsonResult addData(Object data) {
        return new JsonResult(this.isSuccess(), data);
    }
    public JsonResult mark(String msg){
        return new JsonResult(false, msg);
    }
}
